package com.kipling.kio.demo.common.intf;

import com.kipling.kio.core.intf.Packet;
import com.kipling.kio.demo.common.packets.BaseBody;
import com.kipling.kio.json.Json;
import com.kipling.kio.server.ServerGroupContext;

/**
 * @author tanyaowu 
 * 2017年3月27日 下午9:56:16
 */
public abstract class AbsShowcaseBsHandler<T extends BaseBody> implements ShowcaseBsHandlerIntf
{

	/**
	 * 
	 * @author: tanyaowu
	 */
	public AbsShowcaseBsHandler()
	{
	}

	public abstract Class<T> bodyClass();

	public abstract Object handler(Packet packet, T bsBody,ServerGroupContext<Packet, Object> context) throws Exception;

	@Override
	public Object  handler(Packet packet,ServerGroupContext<Packet, Object> context) throws Exception
	{
		//String jsonStr = null;
		T bsBody = null;
		if (packet.getContent() != null)
		{
			//jsonStr = new String(packet.getBody(), Const.CHARSET);
			bsBody = Json.toBean(packet.getContent().toString(), bodyClass());
		}

		return handler(packet, bsBody,context);
	}

}
